<?php
include("../utility/connection.php");
include("../model/mSeminar.php");
include("../model/mUserSeminar.php");
session_start();

if($_SERVER["REQUEST_METHOD"] == "POST") {
    $TopikId = trim(mysql_real_escape_string($_POST["hidIdTopik"]));
    $UserId = trim(mysql_real_escape_string($_POST["hidIdUser"]));
    $UserGroup = trim(mysql_real_escape_string($_POST["hidIdUserGroup"]));

    $results = fnInsertUserSeminar($TopikId,$UserId,$UserGroup);
    
    if ($results) {
        fnGetTopik($TopikId, $UserId);
    } else {
        $_SESSION['re-register']="Re-register";
        $message="Invalid query: ".mysql_error;
        $_SESSION['errmsg']=$message;
        header("location: ../ui/user/oldUser.php");
    }
    
}

function fnGetTopik($TopikId, $UserId) {
    $result = fnSelectSeminar($TopikId);
    $count = mysql_num_rows($result); // number of row
    $seminarResult = mysql_fetch_array($result);
    
    $result1 = fnSelectUserSeminar($TopikId,$UserId);
    $count1 = mysql_num_rows($result1); 
    $seminarUser = mysql_fetch_array($result1);
    
    if ($count == 1) {
        $_SESSION['topikId']=$TopikId;
        $_SESSION['seminarResult']=$seminarResult;
        if ($count1 == 1) {
            $_SESSION['seminarUser']=$seminarUser;
        } else {
            unset($_SESSION['seminarUser']);
            $_SESSION['setDaftar'] = '1';
        }
        header("location: ../ui/user/oldUser.php");
    } else {
        $_SESSION['topikId']=$TopikId;
        unset($_SESSION['seminarResult']);
        unset($_SESSION['seminarUser']);
        unset($_SESSION['setDaftar']);
        header("location: ../ui/user/oldUser.php");
    }
}

?>
